home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / vstsrc / vstdb.c < prev    next >
C/C++ Source or Header  |  1995-01-23  |  17KB  |  499 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81. #include <windows.h>
  82. #include <stdio.h>
  83. #include <stdlib.h>
  84. #include <string.h>
  85. #include <math.h>
  86.  
  87. #include "vstdefs.h"
  88. #include "constant.h"
  89. #include "vsttype.h"
  90. #include "libxtrns.h"
  91.  
  92. BOOL
  93. readSatmodeDB(int version, HWND hwnd, satellite_t **slp, char *dirp, char *filename, char *buf)
  94. {
  95.     char modeLine[120], *cp;
  96.     FILE *fp;
  97.     HANDLE hg;
  98.     mode_t *mp, mode;
  99.     satellite_t *sp;
  100.     int n,r, skipflag;
  101.     double attLat, attLong, sinLat, cosLat, sinLong, cosLong;
  102.  
  103.     sprintf(modeLine,"%s\\%s", (dirp && *dirp) ? dirp : ".", filename);
  104.  
  105.     if ((fp = fopen(modeLine,"r")) == NULL) {
  106.         sprintf(buf, "Cannot open \"%s\".", modeLine);
  107.         usermsg(hwnd, buf);
  108.         return FALSE;
  109.     }
  110.     mp = &mode;
  111.     r = 0;
  112.     skipflag = 0;
  113.  
  114.     while (fp && !feof(fp)) {
  115.         
  116.         mp->beacon       = BEACON * 1.0e6;
  117.         mp->attVecX      = ZERO;
  118.         mp->attVecY      = ZERO;
  119.         mp->attVecZ      = ZERO;
  120.         mp->perigeePhase = ZERO;
  121.         mp->maxPhase     = MAXPHASE;
  122.         mp->alias[0]     = 0;
  123.         mp->nmodes       = 0;
  124.  
  125.         if (getline(modeLine, 100, fp) == NULL)
  126.                 break;
  127.  
  128.         if (modeLine[0] == '#')
  129.             continue;
  130.  
  131.         if (skipflag && !(modeLine[0] == 0 || modeLine[0] == '$'))
  132.             continue;
  133.             
  134.         if (modeLine[0] == '$' || modeLine[0] == 0) {
  135.             skipflag = 0;
  136.             continue;
  137.         }
  138.         
  139.         cp = strtok(modeLine,":= \t");
  140.         if (cp && strncmp(cp,"Satellite",9) == 0) {
  141.             cp = strtok(NULL, ":");
  142.             if (cp) {
  143.                 cp = stripLeadingSpace(cp);
  144.                 if (cp) {
  145.                     stripTrailingSpace(cp);
  146.                     sp = findSatbyName(slp, cp);
  147.                     if (!sp) {
  148.                         skipflag = 1;
  149.                         continue;
  150.                     }
  151.                 }
  152.             }
  153.         }
  154.         else
  155.             continue;
  156.         
  157.         cp = strtok(NULL, ":= \t");
  158.         if (cp) {
  159.             stripTrailingSpace(cp);
  160.             if (strncmp(cp, "Alias", 5) == 0) {
  161.                 cp = strtok(NULL, ":");
  162.                 if (cp) {
  163.                     cp = stripLeadingSpace(cp);
  164.                     if (cp) {
  165.                         stripTrailingSpace(cp);
  166.                         strncpy(mp->alias, cp, sizeof(mp->alias) -1);
  167.                         cp = strtok(NULL, ":= \t");
  168.                         if (cp)
  169.                             cp = stripLeadingSpace(cp);
  170.                     }
  171.                 }
  172.             }
  173.             if (cp && strncmp(cp, "Beacon", 6) == 0) {
  174.                 cp = strtok(NULL, ":= \t");
  175.                 if (cp)
  176.                     mp->beacon = atof(cp) * 1.0e6;
  177.             }
  178.         }
  179.         r = 0;
  180.         do {
  181.             n = 0;
  182.             if (getline(modeLine, 100, fp) == NULL)
  183.                 break;
  184.             if (modeLine[0] == '#' || modeLine[0] == 0)
  185.                 continue;
  186.             if (modeLine[0] == '$')
  187.                 break;
  188.  
  189.             cp = strtok(modeLine, ":");
  190.             if (cp) {
  191.                 if (strncmp(cp, "Perigee Phase", 13) == 0) {
  192.                     cp = strtok(NULL, " \t");
  193.                     if (cp) {
  194.                         mp->perigeePhase = atof(cp);
  195.                         n = 1;
  196.                     }
  197.                 }
  198.                 if (strncmp(cp, "Blon/Blat", 9) == 0) {
  199.                     cp = strtok(NULL, " \t");
  200.                     if (cp) {
  201.                         attLong = atof(cp);
  202.                         cp = strtok(NULL, " \t");
  203.                         if (cp) {
  204.                             attLat = atof(cp);
  205.                             n = 1;
  206.                             attLat   *= CDR;
  207.                             attLong  *= CDR;
  208.  
  209.                             cosLat   = cos(attLat);
  210.                             sinLat   = sin(attLat);
  211.                             cosLong  = cos(attLong);
  212.                             sinLong  = sin(attLong);
  213.  
  214.                             mp->attVecX = cosLong * cosLat;
  215.                             mp->attVecY = sinLong * cosLat;
  216.                             mp->attVecZ = sinLat;
  217.                             if (sp)
  218.                                 sp->s_flags |= SF_ATTITUDE;
  219.                         }
  220.                     }
  221.                 }
  222.                 if (strncmp(cp, "Max Phase", 9) == 0) {
  223.                     cp = strtok(NULL, " \t");
  224.                     if (cp) {
  225.                         mp->maxPhase = atof(cp);
  226.                         n = 1;
  227.                     }
  228.                 }
  229.                 mp->mds[r].modeStr[0] = 0;   
  230.                 if (strncmp(cp, "Mode", 4) == 0) {
  231.                     cp = strtok(NULL, " \t");
  232.                     if (cp) {
  233.                         mp->mds[r].minPhase = (int) (atof(cp) + 0.5);
  234.                         cp = strtok(NULL, " \t'");
  235.                         if (cp) {
  236.                             mp->mds[r].maxPhase = (int) (atof(cp) + 0.5);
  237.                             cp = strtok(NULL, "'");
  238.                             if (cp) {
  239.                                 strncpy(mp->mds[r].modeStr, cp, 2);
  240.                                 n = 1;
  241.                                 if (r < (MAXMODES -1))
  242.                                     r++;
  243.                             }
  244.                         }
  245.                     }
  246.                 }
  247.             }
  248.         } while (n);
  249.         mp->nmodes = r;
  250.         hg = GlobalAlloc(GPTR, sizeof(mode_t));
  251.         if (hg == NULL) {
  252.             if (fp)
  253.                 fclose(fp);
  254.             sprintf(buf,"Out of memory");
  255.             return FALSE;
  256.         }
  257.         if (sp) {
  258.             sp->s_modep = (mode_t *) GlobalLock(hg);
  259.             *sp->s_modep = *mp;
  260.             GlobalUnlock(hg);
  261.         }
  262.     }
  263.     if (fp)
  264.         fclose(fp);
  265.     return TRUE;
  266. }
  267.  
  268. static rotinfo_t *rotp;
  269. static radinfo_t *radp;
  270.  
  271. static rotinfo_t *
  272. findRotbyModel(char *name)
  273. {
  274.     register rotinfo_t *rp;
  275.  
  276.     for (rp = rotp; rp; rp = rp->rot_next)
  277.         if (cistrcmp(rp->rot_name, name) == 0)
  278.             return rp;
  279.             
  280.     return NULL;
  281. }
  282.  
  283. static radinfo_t *
  284. findRadiobyModel(char *name)
  285. {
  286.     register radinfo_t *rp;
  287.  
  288.     for (rp = radp; rp; rp = rp->rad_next)
  289.         if (cistrcmp(rp->rad_name, name) == 0)
  290.             return rp;
  291.             
  292.     return NULL;
  293. }
  294.  
  295. BOOL
  296. readRotDB(int version, HWND hwnd, rotinfo_t **rpp, char *dirp, char *filename, char *buf)
  297. {
  298.     char line[120], *cp;
  299.     char name[80], driver[80];
  300.     FILE *fp;
  301.     rotinfo_t *rp;
  302.     HANDLE hg;
  303.     int index;
  304.  
  305.     hg = NULL;
  306.     index = 0;
  307.     rp = *rpp = NULL;
  308.     
  309.     sprintf(line,"%s\\%s", (dirp && *dirp) ? dirp : ".", filename);
  310.  
  311.     if ((fp = fopen(line,"r")) == NULL) {
  312.         sprintf(buf, "Cannot open \"%s\".", line);
  313.         return FALSE;
  314.     }
  315.  
  316.     while (fp && !feof(fp)) {
  317.         if (getline(line, sizeof line - 1, fp) == NULL)
  318.             break;
  319.  
  320.         if ((line[0] == '#') || (strlen(line) == 0))
  321.             continue;
  322.  
  323.         cp = strtok(line, ":= \t");
  324.         if (!cp)
  325.             continue;
  326.  
  327.         stripTrailingSpace(cp);
  328.         if (!*cp)
  329.             continue;
  330.  
  331.         if (cistrcmp(cp, "model"))
  332.             continue;
  333.  
  334.         cp = strtok(NULL, ":= \t");
  335.         if (!cp)
  336.             continue;
  337.  
  338.         stripTrailingSpace(cp);
  339.         if (!*cp)
  340.             continue;
  341.  
  342.         if (findRotbyModel(cp)) {
  343.             sprintf(buf,"Duplicate entry for %s in '%s'", cp, filename);
  344.             usermsg(hwnd, buf);
  345.             continue;
  346.         }
  347.         strncpy(name, cp, sizeof(name)-1);
  348.  
  349.         cp = strtok(NULL, ":= \t");
  350.         if (!cp)
  351.             continue;
  352.         stripTrailingSpace(cp);
  353.  
  354.         if (!*cp)
  355.             continue;
  356.  
  357.         if (cistrcmp(cp,"drv"))
  358.             if (cistrcmp(cp,"driver"))
  359.                 continue;
  360.  
  361.         cp = strtok(NULL, ":= \t");
  362.         if (!cp)
  363.             continue;
  364.  
  365.         stripTrailingSpace(cp);
  366.         if (!*cp)
  367.             continue;
  368.         strncpy(driver, cp, sizeof(driver) -1);
  369.         
  370.         hg = GlobalAlloc(GPTR, sizeof(*rp));
  371.         if (hg == NULL) {
  372.             if (fp)
  373.                 fclose(fp);
  374.             strcpy(buf,"out of memory reading rotator data file");
  375.             return FALSE;
  376.         }
  377.         if (rp) {
  378.             rp->rot_next = (rotinfo_t *) GlobalLock(hg);
  379.             rp = rp->rot_next;
  380.         }
  381.         else
  382.             rp = rotp = (rotinfo_t *) GlobalLock(hg);
  383.  
  384.         rp->rot_next = NULL;
  385.         rp->rot_index = index++;
  386.         strncpy(rp->rot_name, name, sizeof(rp->rot_name));
  387.         strncpy(rp->rot_driver, driver, sizeof(rp->rot_driver));
  388.  
  389.         GlobalUnlock(hg);
  390.     }
  391.     if (fp)
  392.         fclose(fp);
  393.  
  394.     *rpp = rotp;
  395.     
  396.     return TRUE;
  397. }
  398.  
  399.  
  400. BOOL
  401. readRadDB(int version, HWND hwnd, radinfo_t **rpp, char *dirp, char *filename, char *buf)
  402. {
  403.     char line[120], *cp;
  404.     char name[32], driver[64];
  405.     FILE *fp;
  406.     radinfo_t *rp;
  407.     HANDLE hg;
  408.     int index;
  409.  
  410.     hg = NULL;
  411.     rp = *rpp = NULL;
  412.     index = 0;
  413.     
  414.     sprintf(line,"%s\\%s", (dirp && *dirp) ? dirp : ".", filename);
  415.  
  416.     if ((fp = fopen(line,"r")) == NULL) {
  417.         sprintf(buf, "Cannot open \"%s\".", line);
  418.         return FALSE;
  419.     }
  420.  
  421.     while (fp && !feof(fp)) {
  422.         if (getline(line, sizeof line - 1, fp) == NULL)
  423.             break;
  424.  
  425.         if ((line[0] == '#') || (strlen(line) == 0))
  426.             continue;
  427.  
  428.         cp = strtok(line, ":= \t");
  429.         if (!cp)
  430.             continue;
  431.  
  432.         stripTrailingSpace(cp);
  433.         if (!*cp)
  434.             continue;
  435.  
  436.         if (cistrcmp(cp, "Model"))
  437.             continue;
  438.  
  439.         cp = strtok(NULL, ":= \t");
  440.         if (!cp)
  441.             continue;
  442.  
  443.         stripTrailingSpace(cp);
  444.         if (!*cp)
  445.             continue;
  446.  
  447.         if (findRadiobyModel(cp)) {
  448.             sprintf(buf,"Duplicate entry for %s in '%s'", cp, filename);
  449.             usermsg(hwnd, buf);
  450.             continue;
  451.         }
  452.         strncpy(name, cp, sizeof(name)-1);
  453.         cp = strtok(NULL, ":= \t");
  454.         if (!cp)
  455.             continue;
  456.         stripTrailingSpace(cp);
  457.         if (!*cp)
  458.             continue;
  459.         if (cistrcmp(cp,"driver"))
  460.             if (cistrcmp(cp,"drv"))
  461.                 continue;
  462.         cp = strtok(NULL, ":= \t");
  463.         if (!cp)
  464.             continue;
  465.         stripTrailingSpace(cp);
  466.         if (!*cp)
  467.             continue;
  468.         strncpy(driver, cp, sizeof(driver) -1);
  469.  
  470.         hg = GlobalAlloc(GPTR, sizeof(*rp));
  471.         if (hg == NULL) {
  472.             if (fp)
  473.                 fclose(fp);
  474.             sprintf(buf,"Out of memory");
  475.             return FALSE;
  476.         }
  477.         if (rp) {
  478.             rp->rad_next = (radinfo_t *) GlobalLock(hg);
  479.             rp = rp->rad_next;
  480.         }
  481.         else
  482.             radp = rp = (radinfo_t *) GlobalLock(hg);
  483.             
  484.         rp->rad_next = NULL;
  485.         rp->rad_index = index++;
  486.         strncpy(rp->rad_name, name, sizeof(rp->rad_name));
  487.         strncpy(rp->rad_driver, driver, sizeof(rp->rad_driver));
  488.  
  489.         GlobalUnlock(hg);
  490.     }
  491.     if (fp)
  492.         fclose(fp);
  493.         
  494.     *rpp = radp;
  495.     
  496.     return TRUE;
  497. }
  498.  
  499.